﻿<?php
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('Common_Model');

class Model_LostProperty extends Common_Model {
	function __construct() {
		parent::Common_Model();
		$this->_tb = FLEA::getSingleton('Table_LostProperty');
	}

	function getList($type = 'index', $page = 0, $pageSize = 15, $pagerData = true) {
		FLEA::loadHelper('pager');
		$fields = 'property_id, number, name, created, status';
		$cond = null;

		$pager = new FLEA_Helper_Pager($this->_tb, $page, $pageSize, $cond, 'created desc');
		$lists = $pager->findAll($fields);
		foreach ($lists as $k => $v)
			$lists[$k]['important'] = 1 == $v['important'] ? 'red' : '';

		$viewData['lists'] = $lists;
		if ( true == $pagerData )
			$viewData['pagerData'] = $pager->getPagerData();
		return $viewData;
	}
	
	function getInfo($id) {
		$result = $this->_tb->find('property_id = ' . $id);
		return $result;
	}
	
	function insert($row) {
		$resutl = $this->_tb->create($row);
		return $result;
	}
	
	function delete($id) {
		$resutl = $this->_tb->removeByPkv($id);
		return $result;
	}
	
	function update($row) {
		$resutl = $this->_tb->update($row);
		return $result;
	}
	
	function getForm($type, $data = null) {
		return $this->_tb->form($type, $data);
	}
	
	function getTodayProperties() {	//取得当天的失物数量
		$today = date('Y-m-d');
		$result = count($this->_tb->findAllByField ('created', $today)) + 1;
		return $result;
	}
	
	function getCurrentNumber() {	//得到当前的失物编号
									//这个有漏洞,不易发现~
		$number = $this->getTodayProperties();
		if ($number < 10) {
			$number = '0' . $number;
		}
		$result = date('Ymd') . $number;
		return $result;
	}
}